package com.unionftech.crm_android.ui

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.unionftech.common.aspectj.LoginFilter
import com.unionftech.common.base.BaseActivity
import com.unionftech.content_user.ui.UFSkinSettingFragment
import com.unionftech.crm_android.R

class UFSkinSettingActivity : BaseActivity() {
    private lateinit var mFragment: UFSkinSettingFragment

    companion object {
        @JvmStatic
        fun startThis(context: Context) {
            val intent = Intent(context, UFSkinSettingActivity::class.java)
            if (context !is Activity) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            }
            context.startActivity(intent)
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    override fun initLayout() = R.layout.activity_uf_skin_setting

    override fun initData() {
        super.initData()
        mFragment = UFSkinSettingFragment.newInstance()
    }

    override fun statusBar() {
        fullScreen()
    }

    override fun setListener() {
        super.setListener()
        mFragment.setCallBack {
            gotoAppMain()
        }
    }

    /**
     * 这里为什么要重新创建一个方法，而不是直接使用checkEnterApp,
     * 因为AspectJ无法在 kotlin的函数语法糖中执行
     */
    private fun gotoAppMain() {
        checkEnterApp()
    }

    @LoginFilter
    private fun checkEnterApp() {
        finish()
    }

    override fun setView() {
        super.setView()
        hideTitleBar()
        val beginTransaction = supportFragmentManager.beginTransaction()
        beginTransaction.add(R.id.fl_skin_content, mFragment)
        beginTransaction.commitNowAllowingStateLoss()
        supportFragmentManager.executePendingTransactions()
    }

}